<?php

class UserEvent extends CActiveRecord
{
	
	/**
	 * Returns the static model of the specified AR class.
	 * @return CActiveRecord the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{user_event}}';
	}
	
	/*
	 * @ 重新relations
	 *   映射用户表
	 */
	public function relations()
	{
		return array(
			'users' => array(self::BELONGS_TO, 'Users', 'user_id'),
		);
	}

	/*
	 * @ 创建成功后
	 */
	public function addUserEvent($user_id,$content)
	{
		$date = date('Y-m-d');
		$criteria=new CDbCriteria;
		$criteria->condition='user_id=:user_id AND content=:content AND create_time = :create_time';
		$criteria->params=array(':user_id'=>$user_id,':content'=>$content,'create_time'=>$date);
		$n = self::model()->count($criteria);
		if($n < 1)
		{
			$this->setIsNewRecord(true);
			$this->user_id = $user_id;
			$this->content = $content;
			$this->create_time = $date;
			self::model()->save();
		}
	}
}